#include "stdafx.h"
#include "Gui.h"
#include "Core.h"

namespace {

const char* DefaultSections[] = {
    "Welcome",
    "License",
    "Password",
    "InfoBefore",
    "UserInfo",
    "SelectDir",
    "SelectComponents",
    "SelectProgramGroup",
    "SelectTasks",
    "Ready",
    "Preparing",
    "Installing"
    "InfoAfter",
    "Finished",
    0
};

}

Ui::Ui (Core& aCore)
: mCore(aCore)
{
    const char** Cursor = DefaultSections;
    while (*Cursor) {
        mSections.push_back(*Cursor);
        ++Cursor;
    }
}

Ui::~Ui()
{
    mCore.GuiDestroyed();
}

bool Ui::NextCommandEvent() { return mCore.NextCommand(); }
bool Ui::BackCommandEvent() { return mCore.BackCommand(); }
bool Ui::ShouldSkipSectionEvent(const String& aSection) { return mCore.ShouldSkipSection(aSection); }

int Ui::IndexOfSection(const String& aSection)
{
	auto Start = mSections.cbegin();
	auto Stop = mSections.cend();
	auto Found = std::find(Start, Stop, aSection);

	if (Found == Stop) {
        return -1;
	}

	return static_cast<int>(Found - Start);
}
